<template>
  <div class="video-list-container">
    <el-row class="tabRow" :gutter="20" type="flex" justify="space-around">
      <el-col
        v-for="videoItem in videoData"
        :key="videoItem.id"
        :xl="6"
        :sm="8"
        :md="8"
        :lg="8"
        :offset="0"
      >
        <el-card
          class="tabCard"
          shadow="hover"
          @click.native="toVideo(videoItem.id)"
          :body-style="bodyStyle"
        >
          <el-image class="img" :src="videoItem.image" fit="cover"></el-image>
          <div class="vlogger">
            <span>{{ videoItem.title }}</span>
            <div>
              <span>{{ videoItem.author }}</span>
              <span style="float: right">{{ videoItem.date }}</span>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getRandomVideo } from "../api/videoApi";
export default {
  props: {},
  data() {
    return {
      bodyStyle: {
        padding: "0px",
      },
      videoData: [],
    };
  },
  computed: {
    // 响应式处理每行的视频数量
    showInLg() {
      return function (index) {
        return { "hidden-lg-and-down": index === this.listSize - 1 };
      };
    },
  },
  methods: {
    toVideo(id) {
      this.$router.push({
        name: "video",
        query: {
          id: id,
        },
      });
    },
    getRandomVideo() {
      getRandomVideo(4)
        .then((res) => {
          this.videoData = res.data.data.rows;
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
  mounted() {
    this.getRandomVideo();
  },
};
</script>

<style lang="scss" scoped>
.video-list-container {
  width: 100%;
  height: 250px;
}

.tabRow {
  width: 100%;
  height: 240px;
}

.tabCard {
  width: 300px;
  height: 240px;
}

.vlogger {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.img {
  width: 100%;
  height: 190px;
}
</style>
